import { getDeviceGroupTreeNodeExclude } from '@/api/iot/admin/device';
import { readDriverNodes } from '@/api/iot/admin/driver';
import { AdColumn } from '@/components/AdVxeTable';
import { useI18n } from '@/hooks/web/useI18n';

const { t } = useI18n();

export const columns: AdColumn[] = [
  {
    title: t('entity.idTitle'),
    field: 'Id',
    width: 180,
    visible: false,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'integer',
  },
  {
    title: t('iot.route.device.nameText'),
    field: 'Name',
    width: 200,
    formVisible: true,
    required: true,
    filterable: true,
    dataType: 'string',
  },
  {
    title: t('iot.route.device.descriptionText'),
    field: 'Description',
    width: 200,
    formVisible: true,
    filterable: true,
    dataType: 'string',
    formCustomer: {
      colProps: {
        // span: 24,
        xs: 24, // <576px
        sm: 24, // ≥576px
        md: 24, // ≥768px
        lg: 24, // ≥992px
        xl: 24, // ≥1200px
        xxl: 24, // ≥1600px
        // xxxl: 24, // ≥2000px 3.0
      },
    },
  },
  {
    title: t('iot.route.device.enabledText'),
    field: 'Enabled',
    width: 90,
    formVisible: true,
    formSchema: {
      field: 'Enabled',
      component: 'Switch',
      defaultValue: true,
    },
    filterable: true,
    dataType: 'boolean',
  },
  {
    title: t('iot.route.device.rpclogEnabledText'),
    field: 'RpclogEnabled',
    width: 110,
    formVisible: true,
    formSchema: {
      field: 'RpclogEnabled',
      component: 'Switch',
      defaultValue: true,
    },
    filterable: true,
    dataType: 'boolean',
  },
  {
    title: t('iot.route.device.updWhnChgText'),
    field: 'UpdWhnChg',
    width: 90,
    formVisible: true,
    formSchema: {
      field: 'UpdWhnChg',
      component: 'Switch',
      defaultValue: true,
    },
    filterable: true,
    dataType: 'boolean',
  },
  {
    title: t('iot.route.device.svWhnChgText'),
    field: 'SvWhnChg',
    width: 90,
    formVisible: true,
    formSchema: {
      field: 'SvWhnChg',
      component: 'Switch',
      defaultValue: false,
    },
    filterable: true,
    dataType: 'boolean',
  },
  {
    title: t('iot.route.device.orderNumberText'),
    field: 'OrderNumber',
    width: 80,
    filterable: false,
    dataType: 'number',
  },
  {
    title: t('iot.route.device.enforcePeriodText'),
    field: 'EnforcePeriod',
    width: 110,
    filterable: false,
    dataType: 'number',
  },
  {
    title: t('iot.route.device.cmdPeriodText'),
    field: 'CmdPeriod',
    width: 110,
    filterable: false,
    dataType: 'number',
  },
  {
    title: t('iot.route.device.dvcGrpIdText'),
    field: 'DvcGrpId',
    width: 0,
    visible: false,
    formVisible: true,
    formEditable: true,
    filterable: true,
    dataType: 'integer',
    formRender: {
      name: 'ApiTreeSelect',
      props: {
        api: getDeviceGroupTreeNodeExclude,
        // use name as label
        labelField: 'Name',
        // use id as value
        valueField: 'Id',
        showSearch: true,
        childrenField: 'Items',
        treeNodeFilterProp: 'Name',
        treeDefaultExpandAll: true,
        // not request untill to select
        immediate: true,
      },
    },
  },
  {
    title: t('iot.route.device.dvcGrpNameText'),
    field: 'DvcGrpName',
    width: 150,
    formVisible: false,
    filterable: true,
    filterIndex: 'DvcGrp.Name',
    dataType: 'string',
  },
  {
    title: t('iot.route.device.driverIdText'),
    field: 'DriverId',
    width: 0,
    visible: false,
    formVisible: true,
    formEditable: true,
    filterable: true,
    dataType: 'integer',
    formRender: {
      name: 'ApiSelect',
      props: {
        api: readDriverNodes,
        // use name as label
        labelField: 'Name',
        // use id as value
        valueField: 'Id',
        showSearch: true,
        optionFilterProp: 'Name',
        // not request untill to select
        immediate: true,
      },
    },
  },
  {
    title: t('iot.route.device.driverNameText'),
    field: 'DriverName',
    width: 150,
    formVisible: false,
    filterable: true,
    filterIndex: 'Driver.Name',
    dataType: 'string',
  },
  {
    title: t('iot.route.device.remarkText'),
    field: 'Remark',
    width: 200,
    formVisible: true,
    filterable: true,
    dataType: 'text',
    formCustomer: {
      colProps: {
        // span: 24,
        xs: 24, // <576px
        sm: 24, // ≥576px
        md: 24, // ≥768px
        lg: 24, // ≥992px
        xl: 24, // ≥1200px
        xxl: 24, // ≥1600px
        // xxxl: 24, // ≥2000px 3.0
      },
    },
  },
  {
    title: t('entity.creationAudited.creatorIdTitle'),
    field: 'CreatorId',
    width: 0,
    visible: false,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'string',
  },
  {
    title: t('entity.creationAudited.creatorNameTitle'),
    field: 'CreatorName',
    width: 100,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'CreatorId',
    filterJoin: {
      entityType: 'EaCloud.Pack.Identity.Entities.User,EaCloud.Pack.Identity',
      filterField: 'UserName',
      selectField: 'Id',
    },
    dataType: 'string',
  },
  {
    title: t('entity.creationAudited.creatorNicknameTitle'),
    field: 'CreatorNickname',
    width: 100,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'CreatorId',
    filterJoin: {
      entityType: 'EaCloud.Pack.Identity.Entities.User,EaCloud.Pack.Identity',
      filterField: 'NickName',
      selectField: 'Id',
    },
    dataType: 'string',
  },
  {
    title: t('entity.creationAudited.createdTimeTitle'),
    field: 'CreatedTime',
    width: 180,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'datetime',
  },
  {
    title: t('entity.updateAudited.updaterIdTitle'),
    field: 'UpdaterId',
    width: 0,
    visible: false,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'string',
  },
  {
    title: t('entity.updateAudited.updaterNameTitle'),
    field: 'UpdaterName',
    width: 100,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'UpdaterId',
    filterJoin: {
      entityType: 'EaCloud.Pack.Identity.Entities.User,EaCloud.Pack.Identity',
      filterField: 'UserName',
      selectField: 'Id',
    },
    dataType: 'string',
  },
  {
    title: t('entity.updateAudited.updaterNicknameTitle'),
    field: 'UpdaterNickname',
    width: 100,
    formVisible: true,
    formEditable: false,
    filterable: true,
    filterIndex: 'UpdaterId',
    filterJoin: {
      entityType: 'EaCloud.Pack.Identity.Entities.User,EaCloud.Pack.Identity',
      filterField: 'NickName',
      selectField: 'Id',
    },
    dataType: 'string',
  },
  {
    title: t('entity.updateAudited.updatedTimeTitle'),
    field: 'UpdatedTime',
    width: 180,
    formVisible: true,
    formEditable: false,
    filterable: true,
    dataType: 'datetime',
  },
];
